<template>
    <div>
        <!--面包屑导航区域-->
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/adminIndex' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>

        <!--卡片视图区域-->
        <el-card>
            <!--搜索与添加区域-->
            <el-row :gutter="20">
                <el-col :span="7">
                    <el-input placeholder="请输入查询信息" v-model="queryInfo.query" clearable @clear="getOrdersList">
                        <el-button slot="append" icon="el-icon-search" @click="getOrdersList"></el-button>
                    </el-input>
                </el-col>
            </el-row>

            <!--订单列表区域-->
            <el-table :data="ordersList" border stripe>
                <el-table-column type="index"></el-table-column>
                <el-table-column label="货物名称">
                    <template slot-scope="scope">
                        <el-tag size="medium">{{ scope.row.goodsName }}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="货物数量" prop="goodsNum"></el-table-column>
                <el-table-column label="订单总价" prop="totalPrice"></el-table-column>
                <el-table-column label="货物状态" prop="status">
                    <template slot-scope="scope">
                        <el-tag type="danger" v-if="scope.row.status === '待发货'">待发货</el-tag>
                        <el-tag type="success" v-else-if="scope.row.status === '已签收'">已签收</el-tag>
                        <el-tag type="warning" v-else>运输中</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="下单时间" prop="createTime" :show-overflow-tooltip='true'>
                    <template slot-scope="scope">
                        {{scope.row.createTime | dateFormat}}
                    </template>
                </el-table-column>
                <el-table-column label="更新时间" prop="updateTime" :show-overflow-tooltip='true'>
                    <template slot-scope="scope">
                        {{scope.row.updateTime | dateFormat}}
                    </template>
                </el-table-column>
                <el-table-column label="厂家名称">
                    <template slot-scope="scope">
                        <el-tag size="medium">{{ scope.row.manufacturerName }}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="厂家地址" prop="manufacturerAddress"
                                 :show-overflow-tooltip='true'></el-table-column>
                <el-table-column label="采购员名称">
                    <template slot-scope="scope">
                        <el-tag size="medium">{{ scope.row.buyerName }}</el-tag>
                    </template>
                </el-table-column>
            </el-table>

            <!--分页区域-->
            <el-pagination
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="queryInfo.current"
                    :page-sizes="[2, 3, 5, 10]"
                    :page-size="queryInfo.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </el-card>
    </div>
</template>

<script scoped>
    export default {
        data() {
            return {
                // 获取用户列表的参数对象
                queryInfo: {
                    query: '',
                    // 当前的页数
                    current: 1,
                    // 当前每页显示多少条数据
                    pageSize: 7
                },
                ordersList: [],
                total: 0
            }
        },
        created() {
            this.getOrdersList()
        },
        methods: {
            async getOrdersList() {
                var result = await this.$http.get('orders/selectAll', {params: this.queryInfo})
                if (result.data.status !== 200) {
                    return this.$message.error("获取订单列表失败！")
                }
                this.ordersList = result.data.data.records
                this.total = result.data.data.total
            },
            //监听pagesize改变的事件
            handleSizeChange(newSize) {
                this.queryInfo.pageSize = newSize
                this.getOrdersList()
                this.queryInfo.pageSize = 7
            },
            //监听页码值改变的事件
            handleCurrentChange(newPage) {
                this.queryInfo.current = newPage
                this.getOrdersList()
                this.queryInfo.current = 1
            }
        }
    }
</script>

<style scoped>
    .el-breadcrumb {
        margin-bottom: 15px;
        font-size: 12px;
    }

    .el-card {
        box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15) !important;
    }

    .el-table {
        margin-top: 15px;
        font-size: 12px;
    }

    .el-pagination {
        text-align: right;
        margin-top: 15px;
    }
</style>
